# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=pycairo
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-cairo")
pkgver=1.20.1
pkgrel=2
pkgdesc="Python bindings for the cairo graphics library (mingw-w64)"
url="https://pycairo.readthedocs.io"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('LGPL' 'MPL')
depends=("${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-ninja")
provides=("${MINGW_PACKAGE_PREFIX}-python3-cairo")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-cairo")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-cairo")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
source=(https://github.com/pygobject/${_realname}/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('1ee72b035b21a475e1ed648e26541b04e5d7e753d75ca79de8c583b25785531b')

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      ../${_realname}-${pkgver}

  meson compile
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  meson test
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" meson install
  shopt -s globstar
  rm ${pkgdir}${MINGW_PREFIX}/**/*.dll.a
  MSYS2_ARG_CONV_EXCL="-d" \
    python -m compileall -q -d"${MINGW_PREFIX}" "${pkgdir}${MINGW_PREFIX}" && \
    python -O -m compileall -q -d"${MINGW_PREFIX}" "${pkgdir}${MINGW_PREFIX}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/"COPYING* -t "${pkgdir}${MINGW_PREFIX}/share/licenses/python-cairo"
}
